package com.heima.controller;


import com.heima.pojo.dto.NodeDto;
import com.heima.pojo.dto.NodeSearchDto;
import com.heima.pojo.vo.NodeSearchVO;
import com.heima.pojo.vo.VendingMachineVo;
import com.heima.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author ljk
 * @since 2024-10-16
 */
@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
@Api(tags = "点位相关接口")
@RequiredArgsConstructor
public class NodeController {
    private final NodeService nodeService;

    @GetMapping("/search")
    @ApiOperation("查看区域详情")
    public NodeSearchVO pageQuery(NodeSearchDto nodeSearchDto){
        return nodeService.pageQuery(nodeSearchDto);
    }

    @PostMapping
    @ApiOperation("新增点位")
    public Boolean insertNode(@RequestBody NodeDto nodeDto){
        nodeService.insertNode(nodeDto);
        return true;
    }

    @GetMapping("/vmList/{nodeId}")
    @ApiOperation("获取点位详情")
    public List<VendingMachineVo> vmList(@PathVariable String nodeId){
        return nodeService.vmList(nodeId);
    }

    @PutMapping("/{nodeId}")
    @ApiOperation("修改点位")
    public Boolean updateNode(@PathVariable String nodeId,@RequestBody NodeDto nodeDto){
        log.info("修改点位：{},id:{}",nodeDto,nodeId);
        nodeService.updateNode(nodeId,nodeDto);
        return true;
    }

    @DeleteMapping("/{nodeId}")
    @ApiOperation("删除点位")
    public Boolean delNode(@PathVariable String nodeId){
        nodeService.delNode(nodeId);
        return true;
    }
}
